<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\UserDonate;
use App\Models\Area;
use App\Models\Partition;
use App\Models\School;
use App\Models\User;
use App\Models\UserFollow;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $user_id = $this->user_id;
        $way = $this->way;
        return Grid::make(new UserFollow(), function (Grid $grid) use ($user_id, $way) {
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->model()
                ->with([$way?'user':'to_user'])
                ->where("type",0)
                ->when($way==0,function ($query) use ($user_id) {
                    $query->where("user_id",$user_id);
                })
                ->when($way==1,function ($query) use ($user_id) {
                    $query->where("to_id",$user_id);
                })
//                ->whereNotNull("mobile")
                ->orderByDesc("id");
            $grid->disableViewButton();
            $grid->disableQuickEditButton();
            $grid->column('id')->sortable();
            $grid->column(($way?'user':'to_user').'.avatar','头像')->image('',50,50);
            $grid->column(($way?'user':'to_user').'.nickname','昵称');
            $grid->column('created_at');
            $grid->quickSearch(['id',($way?'user':'to_user').'.nickname']);
            $grid->paginate(8);
        });
    }


}
